//
//  AppConfig.swift
//  SwiftDevNote
//
//  Created by apple on 2022/3/7.
//

import Foundation
import UIKit

let ScreenWidth = UIScreen.main.bounds.size.width // 屏幕宽度

let ScreenHeight = UIScreen.main.bounds.size.height  // 屏幕高度

let ISDEBUG = {  //是否为测试环境
    
#if DEBUG
    
    return true
#else
    
    return false
#endif
}()
struct AppConfig{
    
    static let current = AppConfig()
    
    // 状态栏高度的
    let StatusBarHeight = { () -> CGFloat in
        
        if #available(iOS 13.0, *){
            let window = UIApplication.shared.connectedScenes
                .filter({$0.activationState == .foregroundActive})
                .map({$0 as? UIWindowScene})
                .compactMap({$0})
                .last?.windows
                .filter({$0.isKeyWindow})
                .last
            
            guard let unwapWindow = window , let unwapScene = unwapWindow.windowScene , let unwapBarManager = unwapScene.statusBarManager  else{
                return 44
            }
            return unwapBarManager.statusBarFrame.size.height
        }
        else{
            
            return UIApplication.shared.statusBarFrame.height
        }
    }()
}

extension Double{
    
    static let LayoutWidth = 375.0  //UI界面设计宽度
    static let LayoutHeight = 812.0  //UI界面设计高度

    /// 宽度适配
    var W : CGFloat{
        get{
            return self / Double.LayoutWidth * ScreenWidth
        }
    }
    /// 高度适配,当需要使用绝对高度的时候使用，防止超出屏幕高度。只可使用在高度上
    var H : CGFloat{
        get{
            return self / Double.LayoutHeight * ScreenHeight
        }
    }
}

